package com.ruoyi.project.dict.kangxizi.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.kangxizi.domain.KangxiZi;
import com.ruoyi.project.dict.kangxizi.service.IKangxiZiService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 康熙字典Controller
 * 
 * @author shixiangwen
 * @date 2021-06-22
 */
@Controller
@RequestMapping("/dict/kangxizi")
public class KangxiZiController extends BaseController
{
    private String prefix = "dict/kangxizi";

    @Autowired
    private IKangxiZiService kangxiZiService;

    @RequiresPermissions("dict:kangxizi:view")
    @GetMapping()
    public String kangxizi()
    {
        return prefix + "/kangxizi";
    }

    /**
     * 查询康熙字典列表
     */
    @RequiresPermissions("dict:kangxizi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KangxiZi kangxiZi)
    {
        startPage();
        List<KangxiZi> list = kangxiZiService.selectKangxiZiList(kangxiZi);
        return getDataTable(list);
    }

    /**
     * 导出康熙字典列表
     */
    @RequiresPermissions("dict:kangxizi:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KangxiZi kangxiZi)
    {
        List<KangxiZi> list = kangxiZiService.selectKangxiZiList(kangxiZi);
        ExcelUtil<KangxiZi> util = new ExcelUtil<KangxiZi>(KangxiZi.class);
        return util.exportExcel(list, "kangxizi");
    }

    /**
     * 新增康熙字典
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存康熙字典
     */
    @RequiresPermissions("dict:kangxizi:add")
    @Log(title = "康熙字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KangxiZi kangxiZi)
    {
        return toAjax(kangxiZiService.insertKangxiZi(kangxiZi));
    }

    /**
     * 修改康熙字典
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        KangxiZi kangxiZi = kangxiZiService.selectKangxiZiById(id);
        mmap.put("kangxiZi", kangxiZi);
        return prefix + "/edit";
    }

    /**
     * 修改保存康熙字典
     */
    @RequiresPermissions("dict:kangxizi:edit")
    @Log(title = "康熙字典", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KangxiZi kangxiZi)
    {
        return toAjax(kangxiZiService.updateKangxiZi(kangxiZi));
    }

    /**
     * 删除康熙字典
     */
    @RequiresPermissions("dict:kangxizi:remove")
    @Log(title = "康熙字典", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kangxiZiService.deleteKangxiZiByIds(ids));
    }
}
